package offer

import (
	sqlc "bp/db/sqlc"
	"bp/internal/render"
	// sharedConv "bp/internal/rpcserver/shared/conv"
	sharedVld "bp/internal/rpcserver/shared/vld"
	"bp/internal/service/com/offer"
	"bp/internal/util"
	offerGrpc "bp/rpc/gen/mwebapi/offer"
	"context"
)

// VldListOffersOfOwnerReq 验证列出所有者可用的优惠项目请求
func (s *OfferMWebApiImp) VldListOffersOfOwnerReq(ctx context.Context, q *sqlc.Queries, req *offerGrpc.ListOffersOfOwnerReq) (ptr *offer.ListOfferPtrsOfOwnerParam, err error) {
	slog := util.NewContextLogger(ctx, s.slog)
	if req.OwnerId < 0 {
		err = render.InvalidArgumentRange("owner_id")
		return
	}
	if !sharedVld.IsIssuer(req.Issuer) {
		err = render.InvalidArgumentValue("issuer")
		return
	}
	ptr = &offer.ListOfferPtrsOfOwnerParam{
		OwnerID: req.OwnerId,
		Issuer:  req.Issuer,
	}
	slog.Infof("offer_imp/query_vld.VldListOffersOfOwnerReq ok")
	return
}

// VldListOffersOfItemIDReq 验证列出商品可用的优惠项目请求
func (s *OfferMWebApiImp) VldListOffersOfItemIDReq(ctx context.Context, q *sqlc.Queries, req *offerGrpc.ListOffersOfItemIDReq) (ptr *offer.ListOfferPtrsOfItemIDParam, err error) {
	slog := util.NewContextLogger(ctx, s.slog)
	if req.OwnerId < 0 {
		err = render.InvalidArgumentRange("owner_id")
		return
	}
	if !sharedVld.IsIssuer(req.Issuer) {
		err = render.InvalidArgumentValue("issuer")
		return
	}
	if req.ItemId < 0 {
		err = render.InvalidArgumentRange("item_id")
		return
	}
	ptr = &offer.ListOfferPtrsOfItemIDParam{
		OwnerID: req.OwnerId,
		Issuer:  req.Issuer,
		ItemID:  req.ItemId,
	}
	slog.Infof("offer_imp/query_vld.VldListOffersOfItemIDReq ok")
	return
}